<template>
    <div>
        <h1>房价信息修改</h1>
        <hr>
        <table class="table">
            <tbody>
                <tr>
                    <td>房间价格</td>
                    <td><input type="text" v-model="data.Price"></td>
                </tr>
                <tr>
                    <td>最大人数</td>
                    <td><input type="text" v-model="data.Num"></td>
                </tr>
                <tr>
                    <td>房间类型</td>
                    <td>
                        <select v-model="data.TId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang" :value="a.TId">{{a.Name}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房间状态</td>
                    <td><input type="checkbox" v-model="data.State">选中为开放，不选中为维修</td>
                </tr>
                <tr>
                    <td>是否出售</td>
                    <td><input type="checkbox" v-model="data.CState">选中为已出售，不选中为未出售</td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="修改" @click="RAdd"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
onMounted(()=>{
    xia()
    Fan()
})

const data = ref({
    "Id": 0,
  "Price": "",
  "Num": 0,
  "TId": 0,
  "State": true,
  "CState": true
})
const route = useRoute()
const Fan = ()=>{
    var e = route.query.Id
    axios.get('https://localhost:7206/api/RoomPrice/RFan',{params:{Id:e}}).then(res=>{
        data.value = res.data
    })
}

const bang = ref([{
    "TId": 1,
    "Name": "毛坯房"
}])
const xia = ()=>{
    axios.get('https://localhost:7206/api/RoomPrice/Xia').then(res=>{
        bang.value = res.data
    })
}
const router = useRouter();
const RAdd = ()=>{
    if(data.value.Price==""){
        alert('房价不能为空')
        return
    }
    if(data.value.Num==0){
        alert('最大人数不能为空')
        return
    }
    
    axios.post('https://localhost:7206/api/RoomPrice/RUpd',data.value).then(res=>{
        if(res.data>0){
            alert('修改成功');
            router.push({path:"/RShow"});
        }
        else{
            alert('修改失败');
        }
    })
}


</script>

<style scoped>

</style>